#!/usr/bin/env python
from optparse import OptionParser
		
if __name__ == "__main__":

	class MyParser(OptionParser):
		def format_description(self, formatter):
			return self.description

	parser = MyParser(description="""
This is a simple wrapper for gtk.MessageDialog, it will take the following options and return a gtk RESPONSE. Details of return value below:

    # RESPONSE_NONE (-1): - The dialogue was destroyed by window manager or programatically with Gtk::Widget#destroy. This is also returned if the response_id is not set.
    # RESPONSE_REJECT (-2): - This identifier is not associated with buttons in built-in dialogues, but you are free to use it yourself.
    # RESPONSE_ACCEPT (-3): - This identifier is not associated with buttons in built-in dialogues, but you are free to use it yourself.
    # RESPONSE_DELETE_EVENT (-4): - Each dialogue is automatically connected to the delete_event signal. While Gtk::Dialog#run is running, this identifier will be returned,but the delete_event will be prevented from destroying the window as normally.
    # RESPONSE_OK (-5): - A Gtk::Stock::OK button was clicked in a built-in dialogue. You are free to use this button or any of the following in your own dialogues.
    # RESPONSE_CANCEL (-6): - A Gtk::Stock::CANCEL button was clicked in a built-in dialogue.
    # RESPONSE_CLOSE (-7): - A Gtk::Stock::CLOSE button was clicked in a built-in dialogue.
    # RESPONSE_YES (-8): - A Gtk::Stock::YES button was clicked in a built-in dialogue.
    # RESPONSE_NO (-9): - A Gtk::Stock::NO button was clicked in a built-in dialogue.
    # RESPONSE_APPLY (-10) - A Gtk::Stock::APPLY button was clicked in a built-in dialogue.
    # RESPONSE_HELP (-11) - A Gtk::Stock::HELP button was clicked in a built-in dialogue.

	""")

	parser.add_option("-t", "--type",type="choice",dest="type",help="Type of the Message Dialog, choose from:info,warning,question,error",choices=["info","warning","question","error"],metavar="TYPE", default="info")
	parser.add_option("-b", "--button",type="choice",dest="button",help="Type of the Buttons, choose from:none,ok,close,cancel,yesno,okcancel",choices=["none","ok","close","cancel","yesno","okcancel"],metavar="TYPE", default="close")	
	parser.add_option("-m","--message",type="string",dest="message",help="message to display",metavar="MESSAGE")
	parser.add_option("-s","--secondarymessage",type="string",dest="secondarymessage",help="secondarymessage to display",metavar="SECONDARYMESSAGE")	

	(options, args) = parser.parse_args()

	if options.message is None:
		print "Must provide a message to display (-m or --message)"
		import sys
		sys.exit(1)
	
	
	import gtk
	typemap={"info":gtk.MESSAGE_INFO,
		 "warning":gtk.MESSAGE_WARNING,
		 "question":gtk.MESSAGE_QUESTION,
		 "error":gtk.MESSAGE_ERROR,
		 }
	buttonmap={"none":gtk.BUTTONS_NONE,
		   "ok":gtk.BUTTONS_OK,
		   "close":gtk.BUTTONS_CLOSE,
		   "cancel":gtk.BUTTONS_CANCEL,
		   "yesno":gtk.BUTTONS_YES_NO,
		   "okcancel":gtk.BUTTONS_OK_CANCEL,
		   }
	
	md = gtk.MessageDialog(parent=None,
			       flags=gtk.DIALOG_DESTROY_WITH_PARENT,
			       type=typemap[options.type],
			       buttons=buttonmap[options.button],
			       message_format=options.message)
	if not options.secondarymessage is None:
		md.format_secondary_text(options.secondarymessage)
		
	a=md.run()
	md.destroy()
	
	import sys
	sys.exit(a)

	
